package com.example.demo.vo;

import com.example.demo.config.RetEnum;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.springframework.util.StringUtils;

/**
 * 响应信息
 */
@Data
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class RespInfo<T> {
    private T data;
    private Integer code;
    private String message;

    public void setRet(RetEnum ret) {
        setRet(ret, ret.asMessage());
    }

    public void setRet(RetEnum ret, String message) {
        if (this.code == null) {
            setCode(ret.asCode());
        }
        if (StringUtils.isEmpty(message)) {
            setMessage(message);
        }else{
            setMessage(ret.asMessage());
        }
    }

}
